<template>
  <div class="goods-hot">
    <h3>{{title}}</h3>
    <!-- 商品区块 -->
    <div class="list">
      <GoodsItem class="goods-item" :goods='item' v-for="(item, index) in goods"
                 :key="index" />
    </div>
  </div>
</template>
<script>
import { computed, ref } from 'vue'
import GoodsItem from '@/views/Category/components/goods-item'
import { findGoodsHot } from '@/api/goods'
export default {
  name: 'GoodsHot',
  components: {
    GoodsItem
  },
  props: {
    type: {
      type: Number,
      default: 1
    },
    goodsId: {
      type: String
    }
  },
  setup (props) {
    // 标题对象
    const titleObj = {
      1: '24小时热销榜',
      2: '周热销榜',
      3: '总热销榜'
    }
    const title = computed(() => {
      return titleObj[props.type]
    })
    console.log(props)

    const goods = ref({})
    findGoodsHot({ id: props.goodsId, type: props.type }).then(({ result }) => {
      console.log(result)
      goods.value = result
    })
    return { title, goods }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
    margin-bottom: 20px;
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .list {
    display: flex;
    align-items: center;
    flex-direction: column;
    .goods-item{
        margin-top: 10px;
        background-color: #fff;
    }
  }
}
</style>
